<template>
  <!-- 今日病人 -->
  <section>
    <table width="100%" border="0">
      <tr>
        <td width="460" style="vertical-align: top;padding-top:5px;">
          <el-button-group v-if="statisticArr.length>0">
            <el-button :type="form.checkStatus===''?'primary':''" @click="onGetDataStatus('')">全部</el-button>
            <el-button
              :type="form.checkStatus===0?'primary':''"
              @click="onGetDataStatus(0)"
            >待检查({{statisticArr[1].count}}人)</el-button>
            <el-button
              :type="form.checkStatus===4?'primary':''"
              @click="onGetDataStatus(4)"
            >检查中({{statisticArr[3].count}}人)</el-button>
            <el-button
              :type="form.checkStatus===1?'primary':''"
              @click="onGetDataStatus(1)"
            >已完成({{statisticArr[2].count}}人)</el-button>
          </el-button-group>
        </td>
        <td style="text-align:right;">
          <el-form :inline="true" @submit.native.prevent="getData(-1)">
            <!-- <el-form-item>
              <el-select style="width:120px;" v-model="form.payStatus" clearable placeholder="收费状态">
                <el-option v-for="(item,index) in payStatusEnum" :key="index" :value="item.id" :label="item.desc"></el-option>
              </el-select>
            </el-form-item>-->
            <el-form-item>
              <patientSearch v-model="form.patientId"></patientSearch>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" circle icon="el-icon-search" native-type="submit"></el-button>
            </el-form-item>
          </el-form>
        </td>
      </tr>
    </table>
    <el-row :gutter="20">
      <el-col
        v-for="(item,index) in tableList"
        :key="index"
        :xs="12"
        :sm="12"
        :md="12"
        :lg="8"
        :xl="6"
        class="reserve-user-list"
      >
        <div :class="['card-box',classToName(item.checkStatusId)]">
          <div class="card-nr">
            <div>
              <img
                v-if="!item.headUrl"
                src="@/img/unknown-avatar.png"
                class="head-img"
                alt
                style="width:70px;height:70px;"
              />
              <img
                v-else
                :src="item.headUrl|imageUrl"
                class="head-img"
                alt
                style="width:70px;height:70px;"
              />
            </div>
            <div style="overflow: hidden;">
              <p class="overflow-omit">
                <span style="font-size:18px;">{{item.patientName}}</span>
                &nbsp;
                （{{item.sexDesc}}&nbsp;
                <span
                  v-if="item.age>17"
                >{{item.age}}岁</span>
                <span v-else>{{item.birthday|toTimeContrast}}</span>）
              </p>
              <div class="overflow-omit">检验：{{item.checkDesc}}</div>
              <div
                class="overflow-omit"
              >{{item.checkStatusDesc}} / {{item.payDesc}} / {{item.createTime|computeHour}}</div>
              <div class="overflow-omit">开单医生：{{item.doctorName}}（{{item.diagnosisTypeDesc}}）</div>
              <div class="overflow-omit">开单时间：{{item.createTime}}</div>
            </div>
          </div>
          <div class="card-footer">
            <div v-if="item.waitFor" @click="onCheckAffirem(item)">待检查({{item.waitFor}})</div>
            <div v-if="item.underWay" @click="onToDetail(item,4)">检查中({{item.underWay}})</div>
            <div v-if="item.execute" @click="onToDetail(item,1)">已完成({{item.execute}})</div>
          </div>
          <!-- <div class="zt-box">{{item.status|changeAssist(reserveTypeArray)}}</div> -->
          <div v-if="item.level" class="vip-box">
            <el-tooltip :content="item.levelName" placement="top">
              <img src="@/img/icon-vip.png" alt />
            </el-tooltip>
          </div>
        </div>
      </el-col>
    </el-row>
    <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br />
    <pager v-model="pager" @change-pagenum="getData"></pager>
    <dialogCheckAffirm v-model="dialogCheckAffirm" :curItem="curItem" @success="onSuccess"></dialogCheckAffirm>
  </section>
</template>
<script>
export default {
  props: ["qxBtns"],
  components: {
    dialogCheckAffirm: () => import("./_com/dialogCheckAffirm.vue"),
    patientSearch: () => import("@/pages/_com/patientSearch.vue")
  },
  data() {
    return {
      dialogCheckAffirm: false,
      curItem: null,
      form: {
        checkType: 0,
        checkStatus: "",
        payStatus: "",
        queryTime: "",
        patientId: ""
      },
      pager: { pageSize: 12, pageNum: 1, total: 0 },
      tableList: [],
      payStatusEnum: [],
      statisticArr: []
    };
  },
  created() {
    let th = this;
    th.getCommonConfigByKey("支付状态").then(res => {
      th.payStatusEnum = res;
    });
    th.getData();
  },
  methods: {
    //已完成
    onExecute() {
      const th = this;
    },
    //查看详情
    onToDetail(item, status) {
      let th = this;
      th.$router.push({
        path: "assistcheckDetail",
        query: th.getUrlToken({
          cureId: th.jiaMi(item.cureId),
          patientId: th.jiaMi(item.patientId),
          status: status
        })
      });
    },
    //确认检查
    onSuccess(count) {
      const th = this;
      th.onToDetail(th.curItem, 4);
    },
    //获取统计
    getStatistic() {
      let th = this;
      let j = {};
      Object.assign(j, th.form);
      delete j.checkStatus;
      th.$api.cureAssiststatistictype(j).then(res => {
        if (res.executed) {
          th.statisticArr = res.data || [];
        }
      });
    },
    getData(type) {
      let th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      let j = {};
      Object.assign(j, th.form, th.pager);
      th.showLoading();
      th.$api.cureAssistpageQuery(j).then(res => {
        if (res.executed) {
          th.tableList = res.dataBody.list || [];
          th.pager.total = res.dataBody.total;
        }
        th.showLoading(false);
      });
      th.getStatistic();
    },
    //切换状态
    onGetDataStatus(type) {
      this.form.checkStatus = type;
      this.getData(-1);
    },
    //确认检查
    onCheckAffirem(obj) {
      let th = this;
      if (!th.qxBtns.affirm) {
        th.$message.warning("权限不足");
        return;
      }
      th.curItem = obj;
      th.dialogCheckAffirm = true;
    },
    //判断类名
    classToName(type) {
      switch (type) {
        case 0:
          return "bg-dfz";
          break;
        case 1:
          return "bg-yjz";
          break;
        case 4:
          return "bg-sy";
          break;
      }
    }
  }
};
</script>
